package leetcode.editor.cn;
//[367]有效的完全平方数
public class ValidPerfectSquare367{
public static void main(String[] args) {
   Solution solution = new ValidPerfectSquare367().new Solution();
    boolean perfectSquare = solution.isPerfectSquare(5);
    System.out.println("ValidPerfectSquare367:main:"+perfectSquare);
}

  //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public boolean isPerfectSquare(int num) {
        if (num == 0 || num == 1)return true;
        int left = 0;
        int right = num;
        while (left <= right){
            int mid = left + (right - left) / 2;
             double i = (double) num/mid;//eg: 2.5= i =  5 / 2
            if (mid == i){// 2== 2.5 false
                return true;
            }else if ( mid > i){
                right = mid - 1;
            }else {
                left = mid + 1;
            }
        }
        return false;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}